package com.nervenets.web.controller.user;

import com.nervenets.web.controller.TokenParams;
import com.nervenets.web.entity.UserToken;
import com.nervenets.web.enumeration.Gender;
import com.nervenets.web.hibernate.domain.User;
import lombok.Data;

import java.io.Serializable;

@Data
public class UserModel implements Serializable {
    private long id;
    private int createTime;
    private String openId;
    private String name;
    private String avatar;
    private Gender gender;
    private String mobile;
    private String idCard;
    private boolean enable;
    private int lastLoginTime;

    private String token;

    public UserModel(User user) {
        this.id = user.getId();
        this.createTime = user.getCreateTime();
        this.openId = user.getOpenId();
        this.name = user.getName();
        this.avatar = user.getAvatar();
        this.gender = user.getGender();
        this.mobile = user.getMobile();
        this.enable = user.isEnable();
        this.lastLoginTime = user.getLastLoginTime();

        this.token = TokenParams.getTokenStr(new UserToken(this.id));
    }
}
